// pages/gsyq/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  tostep3() {
    wx.setStorageSync('link', 'step3')
    wx.navigateTo({
      url: '../step3/step3',
    })
  },
  download() {
    const _ = this;
    wx.showLoading({
      title: '资料较大，请稍后',
    })
    wx.downloadFile({
      // 示例 url，并非真实存在
      url: 'https://sd.offcn.com/zg/wximg/2022/gsk/gs/2.zip',
      success: function (res) {
        console.log(res)
        const filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
            wx.hideLoading({
              success: (res) => {},
            })
          }
        })
      },
      fail(res) {
        console.log(res)
      }
    })
  },
  refresh(){
    wx.showLoading()
    this.onLoad()
    wx.hideLoading()
  },
  yes2() {
    var _ = this;
    _.setData({
      fixed:1
    })
  },
  no2() {
    var _ = this;
    wx.showToast({
      title: '邀请三人才可以领取！',
      icon:'none'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var _ = this;
  
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/kanjia/getxzlist/?actid=47385&callback=?",
      data: {
        phone: wx.getStorageSync('gsyqphone'),
        sstimes: Date.parse(new Date())
      }, //接收参数
      success(res) { //返回
        console.log(res)
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson.lists)
        _.setData({
          lists: theJson.lists
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
  to1() {
    wx.navigateTo({
      url: '../index/index',
    })
  },
  to2() {
    const step = wx.getStorageSync('link')
    if(step != 'step2' || step != 'step3'){
        wx.showToast({
          title: '资料未解锁！',
          icon:'none'
        })
    } else {
      wx.navigateTo({
        url: '../step2/step2',
      })
    }
  
  },
  to3() {
    const step = wx.getStorageSync('link')
    if(step != 'step3'){
        wx.showToast({
          title: '资料未解锁！',
          icon:'none'
        })
    } else {
      wx.navigateTo({
        url: '../step3/step3',
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var _ = this;
    var yqphone = wx.getStorageSync('gsyqphone');
    var isIn = wx.getStorageSync('isIn');
    var area = wx.getStorageSync('area');
    var agent = wx.getStorageSync('agent');
    var page = wx.getStorageSync('page');
    if (!isIn) {
      wx.request({ //发送请求
        url: "https://zg99.offcn.com/index/kanjia/writeyq/?actid=47385&callback=?",
        data: {
          phone: yqphone,
          spid: '1'
        }, //接收参数
        success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson)
          if (theJson.status == 1) {
            wx.setStorageSync('isIn', '1')
          }
        }
      })
    }

    return {
      title: '志在国省，与我偕行！',
      path: 'pages/gsyq/login/login?yqphone=' + yqphone + '&area=' + area + '&agent=' + agent + '&page=' + page,
      success: function (res) {
        console.log(res)
      }

    }
  }
})